#!/usr/bin/perl
# first call
# header("Content-Type: application/octet-stream\r\n\r\n") included.
require 'ChopSet.ph';

$|=1;
sysread(STDIN, $problem, $ENV{CONTENT_LENGTH});
unless($problem =~ m/(.*)\n(\d+)\s+(\d+)/){
	print("data format error: $problem");
	&endCall();
	exit(0);
}
$target = $1;
$allNum = $2;
$myNum  = $3;

# 32(' ') to 126('~')
$startChar = 33;
$endChar = 126;
$diff = int(($endChar-$startChar) / $allNum);
foreach $c (0 .. $diff){
	$result = &r_try(pack("c", $startChar + $c + $diff * ($myNum - 1))
		, qr/$target/);
	if($result ne ''){
		print("found: $result\n");
		&endCall();
		exit(0);
	}
}
print("not found.\n");

# last call.
&endCall();

sub r_try {
	# now string, compiled regex
	my($now, $re) = @_;
	my($result);
	if(length($now) >= 8){
		$result = &trip($now);
		if($result =~ $re){
			return $now;
		}
		return '';
	}
	my($char);
	foreach $char ($startChar .. $endChar){
		$result = &r_try($now. pack("c", $char), $re);
		return $result if($result ne '');
	}
	return '';
}

sub trip($) {
	my $seed = shift;
	my $salt = substr($seed, 1, 2);
	my($precision) = 10;

	$salt =~ tr/\x3A-\x40\x5B-\x60/A-Ga-f/;
	$salt =~ s/[^\.\/0-9A-Za-z]/./g;

	return(substr(crypt($seed, $salt), -$precision));
}

